﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
using System.Web.ModelBinding;
using System.Web.Routing;

namespace Morus.Presentation
{
    public abstract class CompositeView<TView> : ICompositeView
          where TView : class, IView
    {
        private readonly ICollection<TView> _views = new List<TView>();

        protected internal IEnumerable<TView> Views
        {
            get
            {
                return _views;
            }
        }

        public void Add(IView view)
        {
            Check.Argument.IsNotNull(view, "view");

            if (!(view is TView))
            {
                throw new ArgumentException("Expected a view of type {0} but {1} was supplied.".FormatWith(typeof(TView).FullName, view.GetType().FullName));
            }

            _views.Add((TView)view);
        }

        public virtual bool ThrowExceptionIfNoPresenterBound
        {
            get
            {
                return true;
            }
        }

        public abstract event EventHandler Load;
    }
}
